﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using MovieRental.XmlDataService;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace MovieRental.Entities
{
    [XmlEntity("LoanCarts")]
    [DataContract]
    public class LoanCartInfo : BaseEntity<Guid>
    {
        private Guid _customerId;
        private double _cartDiscountValue;
        private DateTime _loanDate;

        public LoanCartInfo()
        {
            Id = Guid.NewGuid();
            Loans = new ObservableCollection<LoanInfo>();
            Loans.CollectionChanged += new NotifyCollectionChangedEventHandler(LoansCollectionChanged);
            LoanDate = DateTime.Now;
        }

        void LoansCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            OnPropertyChanged("Loans");
        }

        public LoanCartInfo(Guid id)
        {
            Id = id;
            Loans = new ObservableCollection<LoanInfo>();
            Loans.CollectionChanged += new NotifyCollectionChangedEventHandler(LoansCollectionChanged);
        }

        [DataMember]
        public Guid CustomerId
        {
            set { SetProperty<Guid>(ref _customerId, value, "CustomerId"); }
            get { return _customerId; }
        }

        [DataMember]
        public double CartDiscountValue
        {
            set { SetProperty<double>(ref _cartDiscountValue, value, "CartDiscountValue"); }
            get { return _cartDiscountValue; }
        }

        [DataMember]
        public DateTime LoanDate
        {
            set { SetProperty<DateTime>(ref _loanDate, value, "LoanDate"); }
            get { return _loanDate; }
        }

        [DataMember]
        public ObservableCollection<LoanInfo> Loans { private set; get; }
    }
}
